package ehcache;


import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;


public final class EHCacheUtil {
	
	private static final CacheManager cacheManager = CacheManager.create();
	
	//15552000 = 3600 * 24 * 30 * 6 = 半年
	private static final Cache mainCache = new Cache("mainCache", 0, false, false, 15552000, 0);

	static{
		//CacheManager.create().addCache(mainCache);
	}
	public static void CreateCache(){

		cacheManager.addCache(mainCache);

		//User u = new User();
		//mainCache.put(new Element("user1", u));
	}
	
	
	public static Object GetFromCache(String cacheKeyName){
		Element e = mainCache.get(cacheKeyName);
		if(e == null)
			return null;
		
		return e.getObjectValue();
	}
	
	public static void SetCache(String cacheKeyName, Object cacheValue){
		mainCache.put(new Element(cacheKeyName, cacheValue));
	}
}
